package com.yytek.nmp.controller;

import java.util.List;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yytek.common.log.annotation.Log;
import com.yytek.common.log.enums.BusinessType;
import com.yytek.common.security.annotation.RequiresPermissions;
import com.yytek.nmp.domain.IotEventHistory;
import com.yytek.nmp.service.IIotEventHistoryService;
import com.yytek.common.core.web.controller.BaseController;
import com.yytek.common.core.web.domain.AjaxResult;
import com.yytek.common.core.utils.poi.ExcelUtil;
import com.yytek.common.core.web.page.TableDataInfo;

/**
 * 事件历史Controller
 * 
 * @author yytek-iot
 * @date 2022-07-13
 */
@Api(value = "事件历史控制器", tags = {"事件历史管理"})
@RestController
@RequestMapping("/eventHistory")
public class IotEventHistoryController extends BaseController
{
    @Autowired
    private IIotEventHistoryService iotEventHistoryService;

    /**
     * 查询事件历史列表
     */
    @ApiOperation("查询事件历史列表")
    @GetMapping("/list")
    public TableDataInfo list(IotEventHistory iotEventHistory)
    {
        startPage();
        List<IotEventHistory> list = iotEventHistoryService.selectIotEventHistoryList(iotEventHistory);
        return getDataTable(list);
    }

    /**
     * 导出事件历史列表
     */
    @ApiOperation("导出事件历史列表")
    @RequiresPermissions("nmp:history:export")
    @Log(title = "事件历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotEventHistory iotEventHistory)
    {
        List<IotEventHistory> list = iotEventHistoryService.selectIotEventHistoryList(iotEventHistory);
        ExcelUtil<IotEventHistory> util = new ExcelUtil<IotEventHistory>(IotEventHistory.class);
        util.exportExcel(response, list, "事件历史数据");
    }

    /**
     * 获取事件历史详细信息
     */
    @ApiOperation("获取事件历史详细信息")
    @RequiresPermissions("nmp:history:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(iotEventHistoryService.selectIotEventHistoryById(id));
    }

    /**
     * 新增事件历史
     */
    @ApiOperation("新增事件历史")
    @RequiresPermissions("nmp:history:add")
    @Log(title = "事件历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IotEventHistory iotEventHistory)
    {
        return toAjax(iotEventHistoryService.insertIotEventHistory(iotEventHistory));
    }

    /**
     * 修改事件历史
     */
    @ApiOperation("修改事件历史")
    @RequiresPermissions("nmp:history:edit")
    @Log(title = "事件历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IotEventHistory iotEventHistory)
    {
        return toAjax(iotEventHistoryService.updateIotEventHistory(iotEventHistory));
    }

    /**
     * 删除事件历史
     */
    @ApiOperation("删除事件历史")
    @RequiresPermissions("nmp:history:remove")
    @Log(title = "事件历史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(iotEventHistoryService.deleteIotEventHistoryByIds(ids));
    }
}
